import { Component } from '@angular/core';

@Component({
  selector: 'app-demo2',
  templateUrl: './demo2.component.html',
  styles: [``]
})
export class Demo2Component {
  data: string[];
  selectedValue;
  loading = false;
  value: string = '';
  ngOnInit() {
    // 下拉列表内容
    this.data = [];
    // 输入框已选中内容
    this.selectedValue = [
      {
        index: 1,
        value: 'test1'
      },
      {
        index: 2,
        value: 'test2'
      }
    ];
  }

  initData(cb) {
    let arr = Array.from({ length: parseInt((Math.random() * 10).toFixed(0)) + 5 }).map((item, key) => {
      return {
        index: key,
        value: this.value + key
      };
    });

    setTimeout(() => {
      cb(arr);
    }, 1000);
  }

  inputChange(e) {
    this.value = e;
    this.loading = true;
    this.initData(data => {
      this.loading = false;
      this.data = data;
    });
  }

  modelChange(e) {
    console.log(e);
  }
}
